var e = {
    API: "https://demo.run.landalf.cn/",
    getWindowSize: function(e) {
        wx.getSystemInfo({
            success: function(t) {
                e.setData({
                    model: t.model,
                    width: t.windowWidth,
                    height: t.windowHeight,
                    topHeight: t.statusBarHeight + 46,
                    pageLength: pages.length
                });
            }
        });
    },
    login: function(e) {
        var t = this;
        wx.login({
            success: function(a) {
                t.post("wx/user/login", {
                    js_code: a.code
                }, function(t) {
                    0 == t.errno && (wx.setStorageSync("token", t.data.token), wx.setStorageSync("phone", t.data.phone), 
                    wx.setStorageSync("wx_id", t.data.wx_id), e(t));
                });
            }
        });
    },
    post: function(e, t, a, n) {
        this.http("POST", e, t, a, n);
    },
    get: function(e, t, a, n) {
        this.http("GET", e, t, a, n);
    },
    http: function(e, t, a, n, l) {
        var o = this, u = a || {}, s = n || function(e) {
            console.log(e);
        }, r = l || function(e) {
            console.log(e);
        }, i = e || "POST", g = {
            "content-type": "application/x-www-form-urlencoded"
        };
        "GET" == i.toUpperCase() && (g = {
            "content-type": "application/json"
        }), wx.getStorageSync("token") && (g.token = wx.getStorageSync("token")), 2 == arguments.length && "function" == typeof u && (s = u);
        var c = this.API;
        t.indexOf("http") > -1 && (c = ""), wx.request({
            url: c + t,
            method: i,
            header: g,
            data: u,
            success: function(u) {
                "function" == typeof s && 404 != u.statusCode && 500 != u.statusCode && 400 != u.statusCode ? u.data.errno >= 1e3 ? (wx.showToast({
                    title: u.data.errmsg + "",
                    icon: "none"
                }), "您还没开启接单" == u.data.errmsg && wx.showModal({
                    title: "您还没开启接单",
                    content: "您可以前往跑男中心设置接单",
                    confirmText: "立即前往",
                    success: function(e) {
                        e.confirm && wx.navigateTo({
                            url: "/pages/runman/status/status"
                        });
                    }
                })) : -1 == u.data.errno ? o.login(function(u) {
                    o.http(e, t, a, n, l);
                }) : 101 == u.data.errno ? wx.showModal({
                    title: "提示",
                    content: u.data.errmsg,
                    confirmText: "关闭",
                    showCancel: !1
                }) : s(u.data) : wx.showToast({
                    title: "接口  错误 " + u.statusCode,
                    icon: "none"
                });
            },
            fail: function(e) {
                console.log("======== 接口  请求失败 ========"), "function" == typeof r && r(e);
            }
        });
    },
    dateFormat: function(e, t, a) {
        var n = void 0;
        n = 1 == e ? parseInt(new Date().valueOf()) + 864e5 : new Date().valueOf();
        var l = new Date(n), o = {
            "M+": l.getMonth() + 1,
            "d+": l.getDate(),
            "h+": t > -1 ? t : l.getHours(),
            "m+": t > -1 ? 0 : l.getMinutes(),
            "s+": t > -1 ? 0 : l.getSeconds(),
            "q+": Math.floor((l.getMonth() + 3) / 3),
            S: l.getMilliseconds()
        };
        /(y+)/.test(a) && (a = a.replace(RegExp.$1, (l.getFullYear() + "").substr(4 - RegExp.$1.length)));
        for (var u in o) new RegExp("(" + u + ")").test(a) && (a = a.replace(RegExp.$1, 1 == RegExp.$1.length ? o[u] : ("00" + o[u]).substr(("" + o[u]).length)));
        return a;
    },
    formatMsgTime: function(e) {
        var t = new Date(e), a = t.getFullYear(), n = t.getMonth() + 1, l = t.getDate(), o = t.getHours(), u = t.getMinutes(), s = (t.getSeconds(), 
        new Date()), r = 0;
        return r = s.getTime() - t.getTime(), r <= 6e4 ? "刚刚" : 6e4 < r && r <= 36e5 ? Math.round(r / 6e4) + "分钟前" : 36e5 < r && r <= 864e5 ? Math.round(r / 36e5) + "小时前" : 864e5 < r && r <= 1296e6 ? Math.round(r / 864e5) + "天前" : r > 1296e6 && a == s.getFullYear() ? n + "-" + l + " " + o + ":" + u : e;
    },
    getTimeOptions: function() {
        var e = [ {
            label: "00:00",
            value: 0
        }, {
            label: "01:00",
            value: 1
        }, {
            label: "02:00",
            value: 2
        }, {
            label: "03:00",
            value: 3
        }, {
            label: "04:00",
            value: 4
        }, {
            label: "05:00",
            value: 5
        }, {
            label: "06:00",
            value: 6
        }, {
            label: "07:00",
            value: 7
        }, {
            label: "08:00",
            value: 8
        }, {
            label: "09:00",
            value: 9
        }, {
            label: "10:00",
            value: 10
        }, {
            label: "11:00",
            value: 11
        }, {
            label: "12:00",
            value: 12
        }, {
            label: "13:00",
            value: 13
        }, {
            label: "14:00",
            value: 14
        }, {
            label: "15:00",
            value: 15
        }, {
            label: "16:00",
            value: 16
        }, {
            label: "17:00",
            value: 17
        }, {
            label: "18:00",
            value: 18
        }, {
            label: "19:00",
            value: 19
        }, {
            label: "20:00",
            value: 20
        }, {
            label: "21:00",
            value: 21
        }, {
            label: "22:00",
            value: 22
        }, {
            label: "23:00",
            value: 23
        } ], t = new Date().getHours(), a = [ {
            label: "立即发货",
            value: -1
        } ];
        for (var n in e) t < e[n].value - 1 && n < e.length - 1 && a.push(e[n]);
        for (var l in e) a.push({
            label: "明天 " + e[l].label
        });
        return a;
    }
};

module.exports = e;